package com.desire.homework;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;


public class _16_GUI打开百度 extends JFrame implements ActionListener {
    JButton btn = new JButton();
    JButton exit = new JButton("退出软件");

    public _16_GUI打开百度(String title) {
        super(title);
        setSize(500, 380);
        setLayout(null);
        btn.setText("打开百度");
        btn.setBounds(100, 250, 100, 25);
        btn.addActionListener(this);
        add(btn);
        exit.setBounds(300, 250, 100, 25);
        exit.addActionListener(this);
        add(exit);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args) {
        new _16_GUI打开百度("词典程序");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btn) {
            int i = JOptionPane.showConfirmDialog(this, "要打开百度码？");
            if (i == 0) {
                Runtime run = Runtime.getRuntime();
                try {
                    run.exec("cmd /k start http://www.baidu.com");
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        } else if (e.getSource() == exit) {
            this.dispose();
            System.exit(0);
        }
    }
}

